<?php 
class GoodsModel extends Model{
	public $table="goods";
	public $validate=array(
	  array('category_cid','nonull','请选择所属分类',2,3),
	  array('brand_bid','nonull','请选择所属品牌',2,3),	
	  array('gname','nonull','商品名称不能为空',2,3),
	   array('price','nonull','价格不能为空',2,3),
	);
	public $auto=array(
	
	  array('sendtime','time','function',2,3),
	  array('user_uid','_uid','method',2,3),
	
	);
	public function _uid(){
		return session('aid');
	}
	/**
	 * 添加
	 */
	 public function addgoods(){
	 	if(!$this->create()) return false;
		if(!K("Goodsdetail")->create()){
			$this->error=K("Goodsdetail")->error;
			return false;
		}
	    $cid=$_POST['category_cid'];
		  $this->data['shop_type_tid']=K('Category')->where("cid={$cid}")->getField('shop_type_tid');
		$this->data['gnumber']=mt_rand(100000, 99999999);
//		p($_POST);die;
//		p($this->data);die;
		$gid=$this->add();
        K("Goodsdetail")->adddetail($gid);
		K("Goodsattr")->addAttr($gid);
		return true;
	 }
	 /**
	  * 编辑
	  */
	  public function editdata(){
	  	if(!$this->create()) return false;
		if(!K("Goodsdetail")->create()){
			$this->error=K("Goodsdetail")->error;
			return false;
		} 
		$this->data['gnumber']=mt_rand(100000, 99999999);
//		p($this->data);die;
		$this->update();
		$gid=Q("post.gid","","intval");
		K("Goodsdetail")->edittail($gid);
		//处理属性表删除在添加
		K("Goodsattr")->where("goods_gid={$gid}")->delete();
		
		K("Goodsattr")->addAttr($gid);
		
		return true;
	  }
}



 ?>